package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.*;

/**
 * 教师实体类
 *
 * @author Teaching Server
 * @since 1.0.0
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "teacherId")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "teachers", indexes = {
        @Index(name = "idx_teacher_name", columnList = "teacherName")
})
public class TeacherEntity {

    /**
     * 教师ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long teacherId;

    /**
     * 教师姓名
     */
    @NotBlank(message = "教师姓名不能为空")
    @Size(max = 50, message = "教师姓名长度不能超过50个字符")
    @Column(nullable = false, length = 50)
    private String teacherName;

    /**
     * 职称
     */
    @Size(max = 50, message = "职称长度不能超过50个字符")
    @Column(length = 50)
    private String title;

    /**
     * 专业领域
     */
    @Size(max = 100, message = "专业领域长度不能超过100个字符")
    @Column(length = 100)
    private String specialty;

    /**
     * 获取完整教师信息
     */
    public String getFullInfo() {
        StringBuilder sb = new StringBuilder();
        sb.append(teacherName);
        if (title != null && !title.isEmpty()) {
            sb.append(" (").append(title).append(")");
        }
        if (specialty != null && !specialty.isEmpty()) {
            sb.append(" - ").append(specialty);
        }
        return sb.toString();
    }

    /**
     * 验证教师信息是否完整
     */
    public boolean isValid() {
        return teacherName != null && !teacherName.trim().isEmpty();
    }
}
